package day05;

import java.util.Arrays;

//数组的演示
public class ArrayDemo {
    public static void main(String[] args) {
        /*
        int[] a = new int[5];//默认值为0
        double[] d = new double[10];//默认值为0.0
        boolean[] b = new boolean[26];//boolean默认值为false

        int[] arr1 = new int[3];//0,0,0
        int[] arr2 = {1, 2, 3};
        int[] arr3 = new int[]{4, 5, 6};
        int[] arr4;
        //arr4={7,8,9}编译错误，此方式只能声明的同时初始化
        arr4 = new int[]{7, 8, 9};
        for (int i = 0; i <= arr4.length-1; ++i) {
            System.out.println(arr4[i]);
        }

        int[] arr = new int[4];
        System.out.println("数组的长度："+arr.length);//长度即元素的个数
        System.out.println("数组的第一个元素为:"+arr[0]);//第一个元素0
        arr[1] =100;
        arr[0] =200;
        arr[2] =3000;
        System.out.println(Arrays.toString(arr));
        Arrays.sort(arr1);
        while (true) {
            System.out.println(Arrays.toString(arr1));
            break;
        }
        System.out.println(arr2[2]);
        System.out.println("!!!!!!!!!!!!!!!!!!!");
        for (int j : arr3) {//foreach循环
            System.out.println(j);
        }
        Arrays.fill(arr,3,4,400);
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        int[] arr5 = new int[5];
        for (int i = 0; i < 5; ++i) {
            arr5[i]=i;
        }
        System.out.println(Arrays.toString(arr5));

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");


         */

        /*
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; ++i) {
            arr[i] = (int) (Math.random() * 99);

        }
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

         */
        int[] a = {1, 2, 4, 56, 7};
        int[] b = new int[9];
        /*
        a:原数组
        1:原数组的起始下标
        b:目标数组
        2:目标数组的起始下标
        3:复制的元素个数
         */
        System.arraycopy(a,1,b,2,3);
        System.out.println(Arrays.toString(b));
        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
        int[] c = {10, 20, 30, 40, 50, 60};
        int[] d = Arrays.copyOf(c, 10);//目标数组长度>原数组长度，末尾补默认值
        int[] e = Arrays.copyOf(c, 3);//目标数组长度<原数组长度，将末尾的截掉
        System.out.println(Arrays.toString(d));
        System.out.println(Arrays.toString(e));
    }
}
